//变量声明解构
// 1.数组解构
let input:[number,number] = [1,2]
function f([first,second]:[number,number]){
    console.log(first)
    console.log(second)
}
f(input)

let [first,...rest] = [1,2,3,4]
console.log(first)
console.log(rest)//[2,3,4]

//2.对象解构
let o={a:'foo',b:12,c:'bar'}
// let {a,b}=o;
let {a,...passthroungh}=o

function keepWholeObject(wholeObject:{a:string,b?:number}){//b可以不存在
    let {a,b=1001}=wholeObject
}

function ff({a='',b=0} = {a:''}):void{

}
ff({a:'yes'})
ff()
ff({})

//扩展数组
let firstone = [1,2]
let second =[3,4]
let bothPlus=[0,...firstone,...second,5]
console.log(bothPlus)

//扩展对象
let defaults={
    food:'spicy',
    price:'$10',
    ambiance:'noisy'
}
let search={...defaults,food:'rich'}//food:'rich'替换spicy  但是在前面的话就不会覆盖
console.log(search)